﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sustainalytics.ReportGenerator.BL;
using Microsoft.VisualStudio.TestTools.UnitTesting;


namespace Sustainalytics.ReportGenerator.BL.Tests
{
    [TestClass()]
    public class BulkDataReaderTests
    {
        

        [TestMethod()]
        public void NextBulkTest()
        {
            var sw = new System.Diagnostics.Stopwatch();
          //  while (true)
            {
                

                {
                    var bulksize = 100;
                    var bulkReader = new BulkDataReader(bulksize, "mongodb://localhost/ClientDW");
                    sw.Start();
                    var lastread = 0;
                    do
                    {
                        var data = bulkReader.NextBulk();
                        lastread = data.Count();
                        //Assert.AreEqual(data.Count(), bulksize);                         
                    }
                    while (lastread == bulksize);
                    sw.Stop();

                    Console.WriteLine("bulk size:  {0}, duration {1}", bulksize, sw.ElapsedMilliseconds);
                    sw.Reset();

                }
            }



            
            {
                sw.Start();
                var bulksize = 1000;
                var bulkReader = new BulkDataReader(bulksize, "mongodb://localhost/ClientDW");
                var data1 = bulkReader.NextBulk();
                var data2 = bulkReader.NextBulk();
                var data3 = bulkReader.NextBulk();


                Assert.AreEqual(data1.Count(), bulksize);
                Assert.AreEqual(data2.Count(), bulksize);
                Assert.AreEqual(data3.Count(), bulksize);
                sw.Stop();

                Console.WriteLine("bulk size:  {0}, duration {1}", bulksize, sw.ElapsedMilliseconds);
                sw.Reset();

            }

            {
                sw.Start();
                var bulksize = 5000;
                var bulkReader = new BulkDataReader(bulksize, "mongodb://localhost/ClientDW");
                var data1 = bulkReader.NextBulk();
                var data2 = bulkReader.NextBulk();
                var data3 = bulkReader.NextBulk();


                Assert.AreEqual(data1.Count(), bulksize);
                Assert.AreEqual(data2.Count(), bulksize);
                Assert.AreEqual(data3.Count(), bulksize);
                sw.Stop();

                Console.WriteLine("bulk size:  {0}, duration {1}", bulksize, sw.ElapsedMilliseconds);
                sw.Reset();

            }
        }
    }
}
